package com.example.androidthings.myproject.server;

import android.content.Context;
import android.content.res.AssetManager;


import com.example.androidthings.myproject.server.httpapi.RequestCarControlHandler;
import com.example.androidthings.myproject.server.httpapi.RequestLoginHandler;
import com.yanzhenjie.andserver.AndServer;
import com.yanzhenjie.andserver.website.AssetsWebsite;
import com.yanzhenjie.andserver.website.*;

/**
 * Created by lai on 2017/7/30.
 */

public class ThingsServer {

    private  Context context;
    private AndServer andServer;

    public ThingsServer(Context context){
        this.context=context;
    }
    public AndServer getServer(){
        if (andServer==null){
            andServer = new AndServer.Build()
                    .port(8080) // 默认是8080，Android平台允许的端口号都可以。
                    .timeout(10 * 1000) // 默认10 * 1000毫秒。
                    .registerHandler("login",new RequestLoginHandler())
                    .registerHandler("carContrl",new RequestCarControlHandler())
                    .website(createWebsite())
                    .build();
        }
        return andServer;


    }
    public AssetsWebsite createWebsite(){
        AssetManager mAssetManager = context.getAssets(); //AssetManager can not be closed.

        return new AssetsWebsite(mAssetManager, "");
    }
}
